Yay, one GList less.
*
* Returns: (element-type GtkWidget) (transfer container): list of widgets anchored at @anchor
**/
-GList*
-gtk_text_child_anchor_get_widgets (GtkTextChildAnchor *anchor)
+GtkWidget **
+gtk_text_child_anchor_get_widgets (GtkTextChildAnchor *anchor,
+ guint *out_len)
{
GtkTextLineSegment *seg = anchor->segment;
- GList *list = NULL;
+ GPtrArray *arr;
GSList *iter;
CHECK_IN_BUFFER_RETURN (anchor, NULL);
-
+
+ g_return_val_if_fail (out_len != NULL, NULL);
g_return_val_if_fail (seg->type == >k_text_child_type, NULL);
iter = seg->body.child.widgets;
+
+ if (!iter)
+ {
+ *out_len = 0;
+ return NULL;
+ }
+
+ arr = g_ptr_array_new ();
while (iter != NULL)
{
- list = g_list_prepend (list, iter->data);
+ g_ptr_array_add (arr, iter->data);
iter = iter->next;
}
/* Order is not relevant, so we don't need to reverse the list
* again.
*/
- return list;
+ *out_len = arr->len;
+ return (GtkWidget **)g_ptr_array_free (arr, FALSE);
}
/**
#include <gdk/gdk.h>
#include <glib-object.h>
+#include <gtkwidget.h>
G_BEGIN_DECLS
GtkTextChildAnchor* gtk_text_child_anchor_new (void);
GDK_AVAILABLE_IN_ALL
-GList* gtk_text_child_anchor_get_widgets (GtkTextChildAnchor *anchor);
+GtkWidget ** gtk_text_child_anchor_get_widgets (GtkTextChildAnchor *anchor,
+ guint *out_len);
GDK_AVAILABLE_IN_ALL
gboolean gtk_text_child_anchor_get_deleted (GtkTextChildAnchor *anchor);
gint byte_index;
GtkTextIter text_iter;
GtkTextChildAnchor *anchor = NULL;
- GList *widgets = NULL;
- GList *l;
+ GtkWidget **widgets = NULL;
+ guint n_widgets = 0;
+ guint i;
/* The pango iterator iterates in visual order.
* We use the byte index to find the child widget.
byte_index = pango_layout_iter_get_index (run_iter);
line_display_index_to_iter (text_layout, display, &text_iter, byte_index, 0);
anchor = gtk_text_iter_get_child_anchor (&text_iter);
- if (anchor)
- widgets = gtk_text_child_anchor_get_widgets (anchor);
+ if (anchor)
+ widgets = gtk_text_child_anchor_get_widgets (anchor, &n_widgets);
- for (l = widgets; l; l = l->next)
+ for (i = 0; i < n_widgets; i++)
{
+ GtkWidget *child = widgets[i];
PangoRectangle extents;
- GtkWidget *child = l->data;
if (_gtk_anchored_child_get_layout (child) == text_layout)
{
}
}
- g_list_free (widgets);
+ g_free (widgets);
}
}
while (pango_layout_iter_next_run (run_iter));